import { ModalForm, ProFormTextArea } from '@ant-design/pro-components';
import { message } from 'antd';
import { updateRechargeRecords } from '../service';
import type { WechatRechargeRecordTableItem } from '../types';

export default (props: { func: () => void; record: WechatRechargeRecordTableItem }) => {
  const { record, func } = props;
  return (
    <ModalForm<{ remark: string }>
      title="添加备注"
      layout="vertical"
      width="30vw"
      modalProps={{
        destroyOnClose: true,
      }}
      trigger={<a>添加备注</a>}
      onFinish={async (values) => {
        const res = await updateRechargeRecords(record.orderNo, values);
        if (res.success) {
          message.success({ content: res.message, key: 'update_recharge_record' });
          func();
          return true;
        }
        message.error({ content: res.message, key: 'update_recharge_record' });
        return false;
      }}
    >
      <ProFormTextArea
        required
        label="添加备注"
        placeholder="请输入订单备注"
        name="remark"
        initialValue={record.orderNo || ''}
      />
    </ModalForm>
  );
};
